package me.itsoo.artemis.framework.repository.mapper.resource;

import me.itsoo.artemis.framework.core.util.Assert;
import me.itsoo.artemis.framework.core.util.StringUtils;

import java.util.StringJoiner;

/**
 * DeleteResource
 *
 * @author zxy
 * @version 0.0.1
 * @since 2023/5/12
 */
public class DeleteResource extends AbstractResource {

    private final String table;

    /**
     * 首节点构造
     *
     * @param table String
     */
    private DeleteResource(String table) {
        this.table = table;
    }

    /**
     * delete
     *
     * @param table String
     * @return QueryResource
     */
    public static DeleteResource delete(String table) {
        Assert.isNotBlank(table, "'table' cannot be empty");
        return new DeleteResource(table);
    }

    @Override
    public String getResourceCommand() {
        final StringJoiner result = new StringJoiner(" ");
        if (StringUtils.isBlank(table)) {
            return result.toString();
        }

        result.add("delete");
        result.add("from");
        result.add(table);
        return result.toString();
    }
}
